<template>
	<view class="page-trans">
		<view class="box box-nopadding bg-box">
			<view class="box-content">
				<view class="main-content">
					<view class="account">当前余额：{{ balance }}{{ symbol.toUpperCase() }}</view>
					<view class="trc20">通道TRC20</view>
					<view class="qrcode-box">
						<qrcode :val="address" :size="qrsize" ref="qrcode"></qrcode>
					</view>
					<view class="receive-address">
						{{ address }}
						<view class="btn btn-primary btn-outline" @click="copyAddress" style="margin-top:15px;">复制地址
						</view>
					</view>
				</view>
				<view class="payway-select">
					<view class="payway-content">
						<view class="current-payway">
							<view class="payway-icon">
								<image :src="logo(symbol)" mode="widthFix"></image>
							</view>
							<view class="payway-text">
								<view class="payway-name">{{ symbol.toUpperCase() }}</view>
								<view class="payway-info">充值币种</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import qrcode from '@/components/qrcode/qrcode.vue';
	import util from '@/common/util.js';
	import api from "@/utils/api/wallet/index.js";

	export default {
		components: {
			qrcode
		},
		data() {
			return {
				balance: 0,
				symbol: "",
				address: "",
				qrsize: 190,
			}
		},
		
		onLoad(e) {
			this.symbol = e.symbol;
			this.balance = e.balance;
			uni.setNavigationBarTitle({
				title: this.symbol.toUpperCase() + "充币"
			})
		},
		onShow() {
			this.getUserAddress();
		},
		mounted() {
			this.showQrcode();
		},
		updated() {
			this.showQrcode();
		},
		methods: {
			async getUserAddress() {
				let res = await api.walletAddress();
				if (res.status == 1) {
					this.address = res.data;
					let user = util.getUser()
					user.wallet_address = this.address;
					uni.setStorageSync("user", user);
				}
			},
			showQrcode() {
				this.$refs.qrcode.creatQrcode();
			},
			logo(symbol) {
				if (this.symbol.toUpperCase() == 'USDT') {
					return "../../../static/icon/usdt-logo-300.png"
				} else {
					return "../../../static/icon/sidlogo.png"
				}
			},
			copyAddress() {
				uni.setClipboardData({
					data: this.address,
					success() {
						uni.showToast({
							title: '已复制',
							icon: 'none'
						});
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-image: url(../../../static/background/layout_bg.png);
		height: 100%;
	}

	.main-content {
		padding: 15px;
	}

	.trc20 {
		text-align: center;
	}

	view {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
	}

	.page-trans {
		padding: 30upx;

		.amount-score {
			display: inline;
			font-size: 12px;
			margin-left: 5px;
			font-weight: bold;
		}

		.box {
			border-radius: 12upx;
			overflow: hidden;

			.box-header {
				border-top: 20px solid #cd9974;

				.box-user-level {
					color: #fff;
					background: #cd9974;
					margin: 0 auto;
					padding: 10upx 30upx;
					margin-top: -20px;
					border-radius: 40px;
					font-weight: bold;
				}
			}

			.box-content {

				.account {
					text-align: center;
					color: #31E8D6;
					font-weight: bold;
				}

				.qrimg {
					text-align: center;
					padding: 0 30upx 30upx 30upx;

					image {
						width: 100%;
					}
				}

				.qrcode-box {
					padding: 30upx;
					text-align: center;
					justify-content: center;

					.qrcode {
						text-align: center;
						margin: 0 auto;
						justify-content: center;

						image {
							width: 100%;
							margin: 0 auto;
						}
					}
				}

				.receive-address {
					color: #888888;
					word-wrap: break-word;
					padding: 0 20upx;
					font-size: 12px;
					text-align: center;
					padding-bottom: 20upx;
				}

				.payway-select {
					padding: 30upx 0;
					flex-direction: row;
					justify-content: center;
					background-color: rgba(0, 0, 0, .5);

					.payway-name {
						font-size: 120%;
					}

					.payway-info {
						color: #666;
						font-size: 12px;
					}

					.icon {
						justify-content: center;
					}

					.current-payway {
						flex-direction: row;


						.payway-icon {
							width: 80upx;
							justify-content: center;
							margin-right: 20upx;

							image {
								width: 100%;
								justify-content: center;
							}
						}

						.payway-text {
							.payway-name {
								line-height: 110%;
							}
						}
					}
				}

				.box-content-info {
					padding: 30upx;
					text-align: center;
					font-size: 100%;
				}

				.button-box {
					flex-direction: row;
					justify-content: center;
					padding: 30upx;
					padding-top: 10upx;
					padding-bottom: 50upx;

					.button {
						color: #4c81df;
						padding: 0 60upx;

						&:first-child {
							border-right: 1px solid #eee;
						}
					}
				}

				.box-amount {
					font-size: 50px;
					text-align: center;
					justify-content: center;

					.price-show {
						font-size: 50px;
						text-align: center;
					}
				}
			}
		}
	}
</style>
